<?php
/**
 * The editing form code for this question type.
 *
 * @copyright &copy; 2012 Karol Danutama
 * @author karoldanutama@gmail.com
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 * @package LX
 *//** */

require_once($CFG->dirroot.'/question/type/edit_question_form.php');

/**
 * Source code editing form definition.
 * 
 * See http://docs.moodle.org/en/Development:lib/formslib.php for information
 * about the Moodle forms library, which is based on the HTML Quickform PEAR library.
 */
class question_edit_sourcecode_form extends question_edit_form {
    function definition_inner(&$mform) {
        // TODO, add any form fields you need.
        // $mform->addElement( ... );
        $mform->addElement('file', 'evaluatorfiles', get_string("evaluatorfiles" , "qtype_sourcecode"));
        $typeoptions = array( 'singlesource' => get_string('Single File'), 'archive' => get_string('Multi File'));
        $mform->addElement('select', 'compiletype', get_string("compiletype" , "qtype_sourcecode"), $typeoptions);
        $typeoptions = array( 'simple' => get_string('Simple'), 'batch' => get_string('Batch'));
        $mform->addElement('select', 'gradingtype', get_string("gradingtype" , "qtype_sourcecode"), $typeoptions);
    }

    function set_data($question) {
        $detail = get_record("question_sourcecode", "question", $question->id);
        if ($detail) {
			$question->compiletype = $detail->compiletype;
			$question->gradingtype = $detail->gradingtype;
		}
        
        parent::set_data($question);
    }

    function validation($data) {
        $errors = array();

        // TODO, do extra validation on the data that came back from the form. E.g.
        // if (/* Some test on $data['customfield']*/) {
        //     $errors['customfield'] = get_string( ... );
        // }

        if ($errors) {
            return $errors;
        } else {
            return true;
        }
    }

    function qtype() {
        return 'sourcecode';
    }
}
?>
